package com.guanghua.brick.html.tag;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.tagext.Tag;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class ContentConfigItemTag extends BodyTagSupport {
	
	private static Log logger = LogFactory.getLog(ContentConfigItemTag.class);
	
	private String text = null;
	private String value = null;
	
	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}
	
	public int doEndTag() throws JspException {
		//找到父亲，并add row
		Tag tag = this.getParent();
		if (tag instanceof ContentConfigTag) {
			
			//生成一行记录
			Map<String, String> map = new HashMap<String, String>();
			map.put(((ContentConfigTag)tag).getTextProperty(), this.text);
			map.put(((ContentConfigTag)tag).getValueProperty(), this.value);
			
			//添加记录
			((ContentConfigTag)tag).addRow(map);
		} else {
			logger.warn("content config item's parent must be config content");
		}
		
		return BodyTagSupport.EVAL_PAGE;
	}

	
}
